package com.woniuxy.ServletContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

/**
 * @auther linke
 * @create 2021-10-19 14:35
 */
@WebServlet("/servletContextDemo06")
public class ServletContextDemo06 extends HttpServlet {
    /**
     * 获取真实路径
     *
     * @param req
     * @param resp
     * @throws ServletException
     * @throws IOException
     */
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("servletContextDemo06...执行了");
        Properties p = new Properties();
//            p.load(ServletContextDemo06.class.getClassLoader().getResourceAsStream("../aaa.properties"));//value4
//            p.load(ServletContextDemo06.class.getClassLoader().getResourceAsStream("aaa.properties"));//value2
//        p.load(ServletContextDemo06.class.getClassLoader().getResourceAsStream("../../aaa.properties"));//value5
        p.load(ServletContextDemo06.class.getClassLoader().getResourceAsStream("../../static/img/aaa.properties"));//value3
        String value = p.getProperty("key");
        System.out.println(value);//


    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }
}
